package com.corecloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.corecloud.entity.SysPermissionEntity;
import com.corecloud.mapper.mysql.SysPermissionMapper;
import com.corecloud.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;


@Service("sysPermissionService")
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysPermissionMapper sysPermissionMapper;


    @Override
    public SysPermissionEntity getByParas(SysPermissionEntity paras) {
        QueryWrapper qw = new QueryWrapper<SysPermissionEntity>();
        if(!StringUtils.isEmpty(paras.getParentId())){
            qw.eq("parent_id",paras.getParentId());
        }
        if(!StringUtils.isEmpty(paras.getId())){
            qw.eq("id",paras.getId());
        }
        if(!StringUtils.isEmpty(paras.getName())){
            qw.like("name",paras.getName());
        }
        if(!StringUtils.isEmpty(paras.getIsValid())){
            qw.eq("is_valid",paras.getIsValid());
        }
        if(!StringUtils.isEmpty(paras.getUrl())){
            qw.eq("url",paras.getUrl());
        }
        return sysPermissionMapper.selectOne(qw);
    }

    @Override
    public List<SysPermissionEntity> getListByParas(QueryWrapper<SysPermissionEntity> qw) {
        return sysPermissionMapper.selectList(qw);
    }

    @Override
    public List<SysPermissionEntity> getListByUserParas(Map<String, Object> map) {
        return sysPermissionMapper.getListByUserParas(map);
    }

    @Override
    public Integer saveInfo(SysPermissionEntity paras) {
        return sysPermissionMapper.insert(paras);
    }

    @Override
    public Integer deleteInfo(Integer id) {
        return sysPermissionMapper.deleteById(id);
    }

    @Override
    public Integer editInfo(SysPermissionEntity paras) {
        return sysPermissionMapper.updateById(paras);
    }

    @Override
    public List<Map<String, Object>> getMapByQuery(QueryWrapper<SysPermissionEntity> qw) {
        return sysPermissionMapper.selectMaps(qw);
    }


}